#include <stdio.h>

int Count_Digit ( const int N, const int D );

int main()
{
    int N, D;
				
    scanf("%d %d", &N, &D);
    printf("%d\n", Count_Digit(N, D));
    return 0;
}

/* 你的代码将被嵌在这里 */

int Count_Digit( const int N ,const int D){

    long n=N;
    int times[10];
	int i;
	for (i =0; i<10;i++)
		times[i]=0; 
    //make it negative
    if (n<0)
        i=-1;
    
    //printf("%ld\n",n );
    
    
    while(n){
        times[(n%10)*i]++;
        
        n/=10;

    }
    return times[D];
    
}
